package com.compass.doctor.ui.home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.doctor.databinding.LayoutConsumableShowItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.ext.onClick
import com.compass.framework.model.Consumable

/**
 * Description： 耗材展示adapter
 * Date:2024/1/11 9:26
 */
class ConsumableShowAdapter :
    BaseRecyclerViewAdapter<Consumable, LayoutConsumableShowItemBinding>() {

    private var onCustomBottomClick: OnCustomButtonClick? = null


    fun setCustomBottomClick(onCustomBottomClick: OnCustomButtonClick?) {
        this.onCustomBottomClick = onCustomBottomClick
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutConsumableShowItemBinding {
        return LayoutConsumableShowItemBinding.inflate(layoutInflater, parent, false)
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutConsumableShowItemBinding>,
        item: Consumable?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvName.text = item.name
            tvUnitPrice.text = "￥${item.price}"
            tvNum.text = item.num
            tvPlusSign.onClick {
                onCustomBottomClick?.onButtonCallBack(position, "plusSign")
            }
            tvMinusSign.onClick {
                onCustomBottomClick?.onButtonCallBack(position, "MinusSign")
            }
            tvAdd.onClick {
                onCustomBottomClick?.onButtonCallBack(position, "add")
            }
        }
    }
}